Find largest and smallest element in an array